//
//  RequestApi+Product.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/8.
//

#import "RequestApi+Product.h"

@implementation RequestApi (Product)

#pragma mark - 是否跳转CPI
+ (void)requestIsJumpToCpiWithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                                     failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, INDEX_IS_JUMP_PRODUCT_OR_CPI] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 获取cpi产品
+ (void)requestProductCpi2WithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,INDEX_PRODUCT_CPI2] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 检查用户放款状态
+ (void)requestCheckUserLoanStatusWithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                                     failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_CHECK_USER_LOAN_STATUS] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 待还款借款列表
+ (void)requestRepaidOrder2WithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                                     failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_REPAID_ORDER2] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 产品打包（首页）
+ (void)requestProductPackaging3WithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                                     failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, PRODUCT_PACKAGING3] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 获取首页需要的用户信用额度
+ (void)requestCreditInfoWithDelegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,USER_CREDITINFO] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 获取借款金额、周期、利息，管理费等信息
+ (void)requestLoanApplyDetailWithApplicationAmount:(NSString *)applicationAmount
                                    applicationTerm:(NSString *)applicationTerm
                                          productId:(NSString *)productId
                                           termUnit:(NSString *)termUnit
                                           delegate:(id <RequestDelegate> _Nullable)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_applicationAmount: readStr(applicationAmount),
        KEY_applicationTerm: readStr(applicationTerm),
        KEY_productId: readStr(productId),
        KEY_termUnit: readStr(termUnit),
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,LOAN_APPLY_DETAIL] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 借款协议信息详情
+ (void)requestContractLoanHtmlInfoWithReqList:(NSMutableArray *)reqList
                        delegate:(id <RequestDelegate> _Nullable)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_reqList: reqList,
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, LOAN_TOTAL_LOAN_INFO2] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 总借款信息
+ (void)requestTotalLoanCalculateFlexibleWithAry:(NSMutableArray *)array
                                        delegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_reqList: array
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,LOAN_TOTAL_LOAN_CALCULATE_FLEXIBLE] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 申请借款
+ (void)requestApplyWithAry:(NSMutableArray *)array
                                        delegate:(id <RequestDelegate>)delegate
                            success:(void (^)(NSDictionary * response, id mark))success
                            failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_gwApplyReqList: array
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD,LOAN_APPLY2] delegate:delegate parameters:dic returnALL:true success:^(NSDictionary *response, id mark) {
        //[GlobalMethod addADJEventWithToken:KEY_Apply_Success phone:[GlobalData sharedInstance].GB_UserModel.phone userId:[GlobalData sharedInstance].GB_UserID];
        if (success != nil) {
            success(response,mark);
        }
    } failure:failure];
}

#pragma mark - 订单列表
+ (void)requestOrderListWithType:(NSString *)type
                        pageSize:(double)pageSize
                         pageNum:(double)pageNum
                        delegate:(id <RequestDelegate>)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_type: readStr(type),
        KEY_pageSize: strDotF(pageSize),
        KEY_pageNum: strDotF(pageNum),
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_LIST2] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 订单详情
+ (void)requestOrderDetailWithPageType:(NSString *)pageType
                               orderNo:(NSString *)orderNo
                        delegate:(id <RequestDelegate> _Nullable)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@?%@=%@&%@=%@",URL_HEAD, ORDER_DETAIL,KEY_orderNo,readStr(orderNo),KEY_pageType,readStr(pageType)] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 展期信息接口
+ (void)requestCalculateDelayWithOrderNo:(NSString *)orderNo
                        delegate:(id <RequestDelegate>)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_orderNo: readStr(orderNo),
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_DELAY_CALCULATE_DELAY] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 还款详情
// 正常还款传1，展期还款传2
+ (void)requestRepaymentDetailWithOrderNo:(NSString *)orderNo
                              requestType:(NSString *)requestType
                        delegate:(id <RequestDelegate>)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    NSDictionary * dic = @{
        KEY_orderNo: readStr(orderNo),  
        KEY_requestType: readStr(requestType),
    };
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_REPAYMENT_DETAIL] delegate:delegate parameters:dic success:success failure:failure];
}

#pragma mark - 是否展示自动复借
+ (void)requestShowAutoApplyWithDelegate:(id <RequestDelegate>)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@",URL_HEAD, ORDER_SHOW_AUTO_APPLY] delegate:delegate parameters:nil success:success failure:failure];
}

#pragma mark - 是否自动复借
+ (void)requestSettledAutoApplyWithOrderNo:(NSString *)orderNo
                                      type:(NSString *)type
                                  delegate:(id <RequestDelegate>)delegate
                         success:(void (^)(NSDictionary * response, id mark))success
                         failure:(void (^)(NSString * errorStr, id mark))failure{
    [RequestApi postUrl:[NSString stringWithFormat:@"%@%@?%@=%@&%@=%@",URL_HEAD, ORDER_SETTLED_AUTO_APPLY,KEY_orderNo,readStr(orderNo),KEY_type,readStr(type)] delegate:delegate parameters:nil success:success failure:failure];
}


@end
